package com.hx.reporter.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.enums.BusinessType;
import com.hx.reporter.domain.GroupUser;
import com.hx.reporter.service.IGroupUserService;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.common.core.page.TableDataInfo;

/**
 * 群组成员Controller
 * 
 * @author ${author}
 * @date 2023-05-28
 */
@RestController
@RequestMapping("/user")
public class GroupUserController extends BaseController {
    @Autowired
    private IGroupUserService groupUserService;

    /**
     * 查询群组成员列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupUser groupUser)
    {
        startPage();
        List<GroupUser> list = groupUserService.selectGroupUserList(groupUser);
        return getDataTable(list);
    }

    /**
     * 导出群组成员列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:export')")
    @Log(title = "群组成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupUser groupUser)
    {
        List<GroupUser> list = groupUserService.selectGroupUserList(groupUser);
        ExcelUtil<GroupUser> util = new ExcelUtil<GroupUser>(GroupUser.class);
        util.exportExcel(response, list, "群组成员数据");
    }

    /**
     * 获取群组成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(groupUserService.selectGroupUserById(id));
    }

    /**
     * 新增群组成员
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:add')")
    @Log(title = "群组成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupUser groupUser)
    {
        return toAjax(groupUserService.insertGroupUser(groupUser));
    }

    /**
     * 修改群组成员
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:edit')")
    @Log(title = "群组成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupUser groupUser)
    {
        return toAjax(groupUserService.updateGroupUser(groupUser));
    }

    /**
     * 删除群组成员
     */
    @PreAuthorize("@ss.hasPermi('reporter:user:remove')")
    @Log(title = "群组成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(groupUserService.deleteGroupUserByIds(ids));
    }
}
